package com.zhaozixiang.generator;

import com.zhaozixiang.generator.controller.CodeGenerator;
import com.zhaozixiang.generator.controller.TableMetaDataReader;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.sql.SQLException;

@SpringBootApplication
public class GeneratorApplication {

    public static void main(String[] args) {
        String dbUrl = "jdbc:mysql://localhost:3306/cooec";
        String username = "root";
        String password = "123456";
        // 文件输出目录
        String outputDir = "D:/generated-code";
        //包名(哪个服务的就替换成对应的)
        String packageName = "com.puhua.pms.server.pm.communicate";

        TableMetaDataReader reader = null;
        try {
            reader = new TableMetaDataReader(dbUrl, username, password);
            CodeGenerator generator = new CodeGenerator(reader);

            // 单表生成
            generator.generate("base_basic", packageName, outputDir);

            // 多表生成
            // String[] tables = {"order", "product"};
            // for (String table : tables) {
            //     generator.generate(table, packageName, outputDir);
            // }

            System.out.println("代码生成完成！路径: " + outputDir);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
